<template>
	<view>
		<view class="header status_bar" :class="scrrol == true ? 'scrrolHeader' : ''">
			<view class="back iconfont icon-xiangzuo1" @tap="backPage"></view>
			<view class="text" :class="scrrol == true ? 'scrrolHeader' : ''">素材中心</view>
		</view>	
		<view class="clear_box"></view>
		
		<view class="material_box">
			<!-- <image :src="url" mode="widthFix"></image> -->
			<video :src="url" controls></video>
		</view>
		
		<view class="confirm" @click="downloadFile()">下载视频</view>
		
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page:1,
				scrrol:false,
				info:'',
				url:'',
				id:0,
			}
		},
		onLoad(e) {
			let that = this;
			that.id = e.id;
			that.loadData();
		},
		methods: {
			loadData() {
				let that = this;
				that.Net._get('auth/material_detail', {id:that.id}, res => {
					if (res.code == 200) {
						that.info = res.data;
						that.url = res.data.content;
					}
				});
			},
			backPage() {
				uni.navigateBack({});
			},
			gotopage(e) {
				let url = e.currentTarget.dataset.url;
				uni.navigateTo({
					url: url
				});
			},
			
			downloadFile() {
				uni.showLoading({
					title: '下载中'
				});
				uni.downloadFile({ //下载
					url: this.url, // 图片下载地址
					success: res => {
						if (res.statusCode === 200) {
							uni.saveImageToPhotosAlbum({ // 保存图片到系统相册。
								filePath: res.tempFilePath, // 图片文件路径
								success: function() {
									uni.showToast({
										title: '图片保存成功',
										icon: 'none',
									});
								},
								fail: function(e) {
									console.log(e);
									uni.showToast({
										title: '图片保存失败',
										icon: 'none',
									});
								},
							});
						}
					}
				});
			}
		},
		onPageScroll: function(Object) {
			//console.log(Object.scrollTop); //实时获取到滚动的值
			if (Object.scrollTop > 28) {
				this.scrrol = true;
				/* #ifdef APP-PLUS */
				/* #endif */
			} else if (Object.scrollTop < 28) {
				this.scrrol = false;
				/* #ifdef APP-PLUS */
				/* #endif */
			}
		},
	}
</script>

<style>
	

	.scrrolHeader{
		background-color: #FF7701 !important;
	}
	
	.material_box{
		width: 92%;
		margin: 4% auto 0;
	}
	
	.material_box image{
		width: 100%;
	}
	
	.material_box video{
		width: 100%;
	}
	
	
	
</style>
